﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SystemCenterSoa.DtoModel.CustomerManagement.DtoModel;
using SystemCenterSoa.PoModel.CustomerManagement.PoModel;
using SystemCenterSoa.Repository.CommonLib;

namespace SystemCenterSoa.Repository.CustomerManagement.Repository
{
    public class CustomerManagementRepository:BaseRepository
    {
        public CustomerManagementRepository(SystemCenterDbSoaContext systemCenterDbSoaContext) : base(systemCenterDbSoaContext)
        {
        }
        /// <summary>
        /// 客户管理信息录入
        /// </summary>
        /// <param name="info"></param>
        /// <param name="info2"></param>
        /// <param name="info3"></param>
        /// <param name="info4"></param>
        /// <returns></returns>
        public int CustomerManagementAdd(CustomerManagementDto info/*, CustomerManagementExtendPo info2, FirstPartyPo info3, SatisfactionSurveyPo info4*/)
        {
            if(info==null)
            {
                return -1;
            }
            //基本信息添加
            var list = new CustomerManagementEssentialPo();
            list.customer_management_number = info.customer_management_number;
            list.customer_management_for_short = info.customer_management_for_short;
            list.customer_management_client_name = info.customer_management_client_name;
            list.customer_management_company_address = info.customer_management_company_address;
            list.customer_management_postal_code = info.customer_management_postal_code;
            list.customer_management_linkman = info.customer_management_linkman;
            list.customer_management_company_tel = info.customer_management_company_tel;
            list.customer_management_fax_number = info.customer_management_fax_number;
            _systemCenterDbSoaContext.CustomerManagementEssentialPo.Add(list);
            //扩展信息添加
            var list1 = new CustomerManagementExtendPo();
            list1.extend_client_english_name = info.extend_client_english_name;
            list1.whether_cooperation_id = info.whether_cooperation_id;
            list1.state_id = info.state_id;
            list1.province_id = info.province_id;
            list1.city_id = info.city_id;
            list1.client_id = info.client_id;
            list1.industry_id = info.industry_id;
            list1.extenf_embranchment = info.extenf_embranchment;
            list1.extend_email = info.extend_email;
            list1.extend_homepage_of_a_company = info.extend_homepage_of_a_company;
            list1.extend_relation_time = info.extend_relation_time;
            list1.extend_relation_department = info.extend_relation_department;
            list1.extend_credit_ratings_id = info.extend_credit_ratings_id;
            list1.extend_intimacy_id = info.extend_intimacy_id;
            list1.extend_bank_name = info.extend_bank_name;
            list1.extend_bank_account = info.extend_bank_account;
            list1.extend_legal_published = info.extend_legal_published;
            list1.extend_taxpayer_registration_number = info.extend_taxpayer_registration_number;
            list1.extend_remark = info.extend_remark;
            list1.enterprise_code = info.enterprise_code;
            _systemCenterDbSoaContext.CustomerManagementExtendPo.Add(list1);

            //甲方负责人信息添加
            var list2 = new FirstPartyPo();
            list2.first_party_name = info.first_party_name;
            list2.first_party_duty = info.first_party_duty;
            list2.first_party_tell = info.first_party_tell;
            list2.first_party_department = info.first_party_department;
            list2.first_party_business_calls = info.first_party_business_calls;
            list2.first_party_homephone = info.first_party_homephone;
            list2.first_party_business_fax = info.first_party_business_fax;
            list2.first_party_homefax = info.first_party_homefax;
            list2.first_party_email = info.first_party_email;
            list2.first_party_remark = info.first_party_remark;
            _systemCenterDbSoaContext.FirstPartyPo.Add(list2);
            //客户满意度调查信息添加
            var list3 = new SatisfactionSurveyPo();
            list3.satisfaction_survey_number = info.satisfaction_survey_number;
            list3.satisfaction_survey_content = info.satisfaction_survey_content;
            list3.satisfaction_survey_time = info.satisfaction_survey_time;
            list3.satisfaction_id = info.satisfaction_id;
            list3.satisfaction_cause = info.satisfaction_cause;
            list3.satisfaction_type_id = info.satisfaction_type_id;
            list3.most_satisfying_aspect = info.most_satisfying_aspect;
            list3.most_usatisfying_aspect = info.most_usatisfying_aspect;
            list3.satisfaction_remark = info.satisfaction_remark;
            _systemCenterDbSoaContext.SatisfactionSurveyPo.Add(list3);
            _systemCenterDbSoaContext.SaveChanges();


            return 1;
            
        }

        /// <summary>
        /// 三级联动
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public List<StateCityPo> GetCity(int id)
        {
            var list = _systemCenterDbSoaContext.StateCityPo.Where(c => c.state_city_lid == id).ToList();
            return list;
        }
        /// <summary>
        /// 客户类型
        /// </summary>
        /// <returns></returns>
        public List<ClientType> GetClientTypes()
        {
            return _systemCenterDbSoaContext.ClientType.ToList();
        }
        /// <summary>
        /// 所属行业
        /// </summary>
        /// <returns></returns>
        public List<IndustryInfo> GetIndustryInfo()
        {
            return _systemCenterDbSoaContext.IndustryInfo.ToList();
        }
        /// <summary>
        /// 信用度
        /// </summary>
        /// <returns></returns>
        public List<CreditRatingsPo> GetCreditRatingsPo()
        {
            return _systemCenterDbSoaContext.CreditRatingsPo.ToList();
        }
        /// <summary>
        /// 亲密度
        /// </summary>
        /// <returns></returns>
        public List<IntimacyPo> GetIntimacyPo()
        {
            return _systemCenterDbSoaContext.IntimacyPo.ToList();
        }
        /// <summary>
        /// 满意度
        /// </summary>
        /// <returns></returns>
        public List<SatisfactionPo> GetSatisfactionPo()
        {
            return _systemCenterDbSoaContext.SatisfactionPo.ToList();
        }
        /// <summary>
        /// 调查方式
        /// </summary>
        /// <returns></returns>
        public List<SatisfactionTypePo> GetSatisfactionTypePo()
        {
            return _systemCenterDbSoaContext.SatisfactionTypePo.ToList();
        }
    }
}
